﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using lx;
using lx.UI;

namespace lxhy
{
    public partial class dcForm : Form
    {

        public dcForm(PageData p)
        {
            InitializeComponent();
            // 定时器
            timer1.Interval = 1000;
            timer1.Enabled = false;
            // 定时间隔：
            Seconds = (int)p["Interval"];
            ShowTime();
            this.timer1.Start();
            if (LXUtil.isNotEmpty(p["RGB"]))
            {
                panelEnhanced1.BackColor = ColorTranslator.FromHtml(p.getString("RGB"));
                label1.BackColor = ColorTranslator.FromHtml("#ffffff");
                panelEnhanced1.BackgroundImage = null;
            }

        }
        //1.声明自适应类实例
        AutoSizeFormClass asc = new AutoSizeFormClass();
        //2. 为窗体添加Load事件，并在其方法Form1_Load中，调用类的初始化方法，记录窗体和其控件的初始位置和大小
        private void dcForm_Load(object sender, EventArgs e)
        {
            label1.Width = 120;
            label1.Height = 60;
            //this.BackColor = ColorTranslator.FromHtml("#272727");
            this.ShowInTaskbar = false;///使窗体不显示在任务栏
            asc.AddControl(this);//窗体内其余控件可能嵌套其它控件(比如panel),故单独抽出以便递归调用
            this.FormBorderStyle = FormBorderStyle.None;     //设置窗体为无边框样式
            this.WindowState = FormWindowState.Maximized;    //最大化窗体 
        }
        //3.为窗体添加SizeChanged事件，并在其方法Form1_SizeChanged中，调用类的自适应方法，完成自适应
        private void AutoForm_SizeChanged(object sender, EventArgs e)
        {
            asc.controlAutoSize(this);
        }

        private void gaunbi_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private int Seconds; 
        private void ShowTime()
        {
            // 显示剩余时间
            label1.Text = string.Format("{0:d2}:{1:d2}",
                    Seconds / 60,
                    Seconds % 60);
        }

        private void timer1_Tick(object sender, EventArgs e)
        {
            if (--Seconds < 1)
            {
                this.Close();
            }
            ShowTime();
        }

    }
}
